# Maintainer: Renato Silva <br.renatosilva@gmail.com>

_realname=libmongoose
pkgbase="mingw-w64-${_realname}-git"
pkgname=(${MINGW_PACKAGE_PREFIX}-${_realname}-git)
provides=(${MINGW_PACKAGE_PREFIX}-${_realname})
conflicts=(${MINGW_PACKAGE_PREFIX}-${_realname})
pkgver=r1938.81d977c
pkgrel=1
url="https://github.com/cesanta/mongoose"
pkgdesc='Embedded web server for C/C++ (mingw-w64)'
license=('GPL2')
arch=('any')
depends=(${MINGW_PACKAGE_PREFIX}-gcc-libs) #${MINGW_PACKAGE_PREFIX}-openssl
makedepends=(${MINGW_PACKAGE_PREFIX}-gcc)
source=(${_realname}::"git+https://github.com/cesanta/mongoose"
        mongoose.pc
        Makefile)
sha256sums=('SKIP'
            '7ff212f0d496a1082282f4722113084f9037d7c501ec90ca124e4de0cc2b2545'
            '223da952e547e57ccdcd0d11278f029a7bc84a7bba6edb7b035194b4a5086dea')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cp Makefile ${_realname}/
  cp mongoose.pc ${_realname}/
}

build() {
  cd "${srcdir}/${_realname}"
  make PREFIX=${MINGW_PREFIX} CC=gcc AR=ar -j1
}

package() {
  cd "${srcdir}/${_realname}"
  make PREFIX=${MINGW_PREFIX} DESTDIR=${pkgdir} install
  install -D -m644 mongoose.pc "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/mongoose.pc"
  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"

  sed -e "s|@@PREFIX@@|${MINGW_PREFIX}|g" \
      -e "s|@@VERSION@@|5.6|g" \
      -i "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/mongoose.pc"
}
